#include "sylar/head.h"
#include <unistd.h>

sylar::Logger::ptr g_logger = SYLAR_LOG_NAME("system");

int count = 0;
sylar::RWMutex s_mutex;

void fun1(){
    while(1) SYLAR_LOG_INFO(SYLAR_LOG_ROOT()) << "name: " << sylar::Thread::GetName()
                             << " this.name: " << sylar::Thread::GetThis()->getName()
                             << " id: " << sylar::GetThreadId()
                             << " this.id" << sylar::Thread::GetThis()->getId();
}

void fun2(){

}

int main(int argc, char** argv){ 
    YAML::Node node = YAML::LoadFile("/home/wk/sylar/bin/conf/log.yml");
    sylar::Config::LoadFromYaml(node);
    std::cout << g_logger->toYamlString() << std::endl;
    SYLAR_LOG_INFO(SYLAR_LOG_ROOT()) << "thread test begin:";
    std::vector<sylar::Thread::ptr> thrs;
    for(int i = 0;i < 5;++i){
        sylar::Thread::ptr thr(new sylar::Thread(&fun1, "name_" + std::to_string(i)));
        thrs.push_back(thr);
    }

    // sleep(80);

    for(int i = 0;i < 5;++i){
        // std::cout << 123 << std::endl;
        thrs[i]->join();
    }
    SYLAR_LOG_INFO(g_logger) << "thread test end" << " count=" << count;

    return 0;
}